#include <iostream>

using namespace std;

typedef long long LL;

int main()
{
    int q; cin >> q;
    while(q--)
    {
        LL l, r; cin >> l >> r;
        LL n = r - l + 1;
        if(n <= 1) cout << -1 << endl;
        else if(n == 2)
        {
            if(l == 1) cout << 0 << endl;
            else cout << -1 << endl;
        }
        else 
        {
            cout << n % 2 << endl;
        }
    }
    return 0;
}